package com.platform.server.redis.impl;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import java.text.SimpleDateFormat;
import java.util.*;



public class RedisTest {
	private static ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath*:spring/*.xml");
	private static RedisClientTemplate jedis = (RedisClientTemplate) ctx.getBean("redisClientTemplate");
	public  static String REDIS_STARMAP_KEY="gameRank";
	public static String IDNAMES="loanterms";


	/**
	 *
	 * 测试排行数据
	 * */
	@Test
	public void testSortSet(){
	}

	/**
	 * *
	 * 测试map排序
	 */
	/*@Test
	public void testSortMap(){
		Map<String,Integer> map = new HashMap<String, Integer>();
		map.put("1001", 80);
		map.put("1002", 80);
		map.put("1003", 60);
		List<Entry<String, Integer>> sortScore =
			new ArrayList<Entry<String, Integer>>((Collection<? extends Entry<String, Integer>>) map.entrySet());
		//排序前
		for(int i=0;i<sortScore.size();i++){
			System.out.println(sortScore.get(i).getKey()+"|"+sortScore.get(i).getValue());
		}
		System.out.println("---------------------------------------------------------");

		// 排序
		Collections.sort(sortScore, new Comparator<Entry<String, Integer>>() {
		    public int compare(Entry<String, Integer> score1,
		            Entry<String, Integer> score2) {
		        return ( score2.getValue()-score1.getValue());
		    }
		});

		//排序后
		for(int i=0;i<sortScore.size();i++){
			System.out.println(sortScore.get(i).getKey()+"|"+sortScore.get(i).getValue());
		}
		sortScore = sortScore.subList(0,2);
		System.out.println(sortScore.size());
	}*/


	/**
	 * *
	 * 测试缓存过期时间
	 */
//	@Test
	public void testRedis(){
		jedis.set("2013", "222");
		long time = Long.valueOf("1480573020");
		jedis.expireAt("2013", time);
		System.out.println(jedis.get("2013"));
	}


	/**
	 * *
	 * list合并
	 */
//	@Test
	/*public void testMergeList(){
		List<Integer> list1 = new ArrayList<Integer>();
		List<Integer> list2 = new ArrayList<Integer>();
		list1.add(1);
		list1.add(2);
		list1.add(3);
		list2.add(2);
		list2.add(3);
		list2.add(4);
		HashSet set = new HashSet(list1);
		set.removeAll(list2);
		list2.addAll(set);
		System.out.println(list2.size());
	}*/

//	@Test
	public void testMap(){
		Map<Integer,Integer> map= new HashMap<Integer, Integer>();
		map.put(0, 11);
		System.out.println(map.size());
	}

//	@Test
	public void testTime(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, 6);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		int day = cal.get(Calendar.DAY_OF_WEEK);
		int monthDay = cal.get(Calendar.DAY_OF_MONTH);
		System.out.println(day+"|"+monthDay);
		cal.set(Calendar.DAY_OF_MONTH, monthDay+9-day);
		System.out.println(sdf.format(cal.getTime()));
	}

//	@Test
	public void testDate(){
		long time = Long.valueOf("1480888800999");
		Date date = new Date(time);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(format.format(date));

	}

}
